package com.getbase.tweetme.resources;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.nio.file.Files;

@Path("/notsmart/receive")
@Produces(MediaType.TEXT_PLAIN)
public class ReceiverResource {

    @POST
    public void receive(String message) {
        System.out.println("called");
        System.out.println(message);

        try{

            OutputStreamWriter writer = new OutputStreamWriter(
                    new FileOutputStream("/tmp/notsmart.feed", true), "UTF-8");
            BufferedWriter fbw = new BufferedWriter(writer);
            fbw.write(message);
            fbw.newLine();
            fbw.write("------------------");
            fbw.newLine();
            fbw.newLine();
            fbw.close();

        } catch (Exception e) {
            System.out.println("ERROR:" + e.getMessage());
        }
    }

}
